#!/bin/sh
echo
echo Fix test1 ...
echo "UPDATE Games SET Site='Warszawa', EventDate='2014.07.14', Event='Najdorf Memorial 2014 - gr.A',TimeControl='40/5400:1800+30';" | sqlite3 -echo -batch games.sqlite
echo "DELETE FROM Games WHERE length(game) < 10;" | sqlite3 -echo -batch games.sqlite
echo
echo Fix test2 ...
echo "UPDATE Games SET Board=substr(Round,3),Round=substr(Round,1,1) WHERE Round LIKE '_.%';" | sqlite3 -echo -batch games.sqlite
#echo "UPDATE Games SET Board=substr(Round,4),Round=substr(Round,1,2) WHERE Round LIKE '__.%';" | sqlite3 -echo -batch games.sqlite # this is in case of more than 9 rounds
echo Fix test3 ...
# Transforms lines:
# "  1  GM  Areshchenko, AlexanderUKR  UKR  2701  2600"
# into:
# "GM|Areshchenko, AlexanderUKR|UKR|2701|2600"
sed -re y/ĄąĆćĘęŁłŃńÓóŚśŹźŻż/AaCcEeLlNnOoSsZzZz/ -e "s/^  [0-9]+  //" -e "s/  /|/g" lista.txt >lista2.txt
# Remove country suffix from player name (note this could be even esier handled in Python script, but I used this as example)
awk -F '|' '{ sub($2,substr($2,1,length($2)-3)); print }' lista2.txt >lista3.txt
./fixtitleelo.py lista3.txt games.sqlite
echo Done
